/**
  * Copyright 2019 bejson.com 
  */
package com.xingkeduo.dto.transter.orderdetail;
import com.alibaba.fastjson.JSON;
import com.xingkeduo.dto.ActivityDto;
import com.xingkeduo.dto.MarketDto;
import com.xingkeduo.dto.OrderDetailResponseDto;
import com.xingkeduo.dto.ShopsDaysTable;
import com.xingkeduo.dto.transter.shop.ShopsDTO;
import com.xingkeduo.pojo.enums.OrderSource;
import com.xingkeduo.utils.DateTimeUtils;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

@Data
public class ContentOrderDetail {

    private Boolean is_passed;
    private Boolean is_finished;
    private Boolean is_commented;
    private Boolean can_share;
    private Boolean is_failed;
    private String row_no;
    private String store_name;
    private String store_id;
    private String starttime;
    private String endtime;
    private String address;
    private String latitude;
    private String longitude;
    private String city_id;
    private String ticket_no;
    private String pay_type;
    private String pay_price;
    private String coupon_price;
    private String reduce_price;
    private String discount_price;
    private String order_no;
    private String appointment_time;
    private String appointment_date;
    private String appointment_short_time;
    private LocalDateTime paytime;
    private String server_name;
    private String service_type;
    private String qrcode_url;
    private String f_ticket_tv_version;
    private String modify_once;
    private String admin_name;
    private String admin_id;
    private String selected_ticket_type;
    private String admin_avatar;
    private Object wait_num;
    private Boolean need_check;
    private Boolean need_cert_check;
    private String activity_name;
    private String activity_id;
    private String all_price;
    private String store_img;
    private List<Hairstyle_list> hairstyle_list;
    private Selected_hair selected_hair;
    private Boolean has_c_la_c_banner;
    private long code_time;
    private Boolean is_revert;
    private String discount_type;
    private String coupon_name;
    private String card_name;
    private String card_price;



    public void covert(ShopsDTO shopsDTO, OrderDetailResponseDto orderDetailResponseDto, List<Hairstyle_list> hairstyle_lists, Selected_hair selected_hair, ShopsDaysTable shopsDaysTable,Object wait_num) {
        if(shopsDTO!=null){
            this.store_name = shopsDTO.getName();
            this.address = shopsDTO.getAddress();
            this.latitude = shopsDTO.getLatitude();
            this.longitude = shopsDTO.getLongitude();
            this.city_id = String.valueOf(shopsDTO.getCitiesId());
            this.store_img  = shopsDTO.getShopsImg();
        }
        this.need_check=false;
        if(StringUtils.isNotEmpty(orderDetailResponseDto.getMarketingType()) && StringUtils.isNotEmpty(orderDetailResponseDto.getCardCouponDetail())){
            this.discount_type = "1".equals(orderDetailResponseDto.getMarketingType())?"coupon":"card";
            MarketDto marketDto = JSON.parseObject(orderDetailResponseDto.getCardCouponDetail(), MarketDto.class);

            if(marketDto!=null && marketDto.getMarketingRefundType()!=null){
                Integer marketingRefundType = marketDto.getMarketingRefundType();
                this.is_revert=marketingRefundType==0?true:false;
                this.need_check= marketDto.getMarketingDiscountType()==3?true:false;
                if("1".equals(orderDetailResponseDto.getMarketingType())){
                    this.coupon_name=marketDto.getMarketingName();
                    this.coupon_price=String.valueOf(orderDetailResponseDto.getMarketingPrice());
                }else {
                    this.card_name = marketDto.getMarketingName();
                    this.card_price=String.valueOf(orderDetailResponseDto.getMarketingPrice());
                }

            }


        }


        if(StringUtils.isNotEmpty(orderDetailResponseDto.getActivityType()) && StringUtils.isNotEmpty(orderDetailResponseDto.getActivityDetail())){

            ActivityDto activityDto = JSON.parseObject(orderDetailResponseDto.getActivityDetail(), ActivityDto.class);

            this.activity_name = activityDto.getActivityName();//店铺活动 暂定，后期完善
            this.activity_id = String.valueOf(activityDto.getActivityId()); //活动id  暂定，后期完善

        }


        this.is_passed=false;  //是否过号
        String status = String.valueOf(orderDetailResponseDto.getStatus().getKey());
        if("5".equals(status)){
            this.is_passed=true;
        }


        if(orderDetailResponseDto.getServiceDown()){
            if(orderDetailResponseDto.getHadComment()){
                this.is_finished = false;// 是否完成
                this.is_commented=true;
            }else {
                this.is_finished = true;// 是否完成
                this.is_commented=false;
            }

        }


        this.can_share = true;// 后期补全
                String key = String.valueOf(orderDetailResponseDto.getStatus().getKey());
                if("-4".equals(key) || "-3".equals(key) || "0".equals(key)){
                    this.is_failed=true;
                }else {
                    this.is_failed=false;
                }

        this.row_no = orderDetailResponseDto.getWaitingLineNo();

        this.store_id = String.valueOf(orderDetailResponseDto.getStoreId());
        if(shopsDaysTable!=null){
            this.starttime =shopsDaysTable.getStarttime();//开始营业时间  暂定
            this.endtime = shopsDaysTable.getEndtime();//结束营业时间，暂定
        }else {
            this.starttime ="";//开始营业时间  暂定
            this.endtime = "";//结束营业时间，暂定
        }


        this.ticket_no = orderDetailResponseDto.getTicketCode();
        this.pay_type = orderDetailResponseDto.getPayTypeName();
        this.pay_price = String.valueOf(orderDetailResponseDto.getPayPrice());
//        this.coupon_price = String.valueOf(orderDetailResponseDto.getMarketingPrice());
        this.reduce_price =String.valueOf(orderDetailResponseDto.getActivityPrice());
        this.discount_price=String.valueOf(orderDetailResponseDto.getCouponPrice());
        this.order_no = orderDetailResponseDto.getOrderNo();
        this.appointment_time = DateTimeUtils.yyyy_MM_dd_HH_mma(orderDetailResponseDto.getAppointmentStartTime());
        this.appointment_date=  DateTimeUtils.yyyy_MM_dd(orderDetailResponseDto.getAppointmentStartTime());
        this.appointment_short_time =  DateTimeUtils.HH_mm(orderDetailResponseDto.getAppointmentStartTime());
        this.paytime = orderDetailResponseDto.getPayTime();
        this.server_name=orderDetailResponseDto.getServiceTypeName();
        this.service_type=orderDetailResponseDto.getServiceTypeId();
        this.qrcode_url=orderDetailResponseDto.getTicketCodeUlr();
        this.f_ticket_tv_version="";// 小票机版本
        this.modify_once=orderDetailResponseDto.getModifyOnce()?"1":"0"; //预约时间修改次数
        this.admin_name = orderDetailResponseDto.getAdminNickName();
        this.admin_id= orderDetailResponseDto.getAdminId();
        this.selected_ticket_type= "3";
        if(OrderSource.BRANCH.equals(orderDetailResponseDto.getOrderSource()) || OrderSource.ALIPAY_SCAN.equals(orderDetailResponseDto.getOrderSource())){
            this.selected_ticket_type="1";
        }
        this.admin_avatar =orderDetailResponseDto.getAdminAvatar();
        this.wait_num =wait_num; //等待人数，暂定，后期完善

        this.need_cert_check = false;// //是否需要认证 暂定，后期完善

        this.all_price = String.valueOf(orderDetailResponseDto.getAllPrice());

        this.hairstyle_list = hairstyle_lists;
        this.selected_hair = selected_hair;

        this.has_c_la_c_banner = true;//是否有c拉c banner

        String storeId =orderDetailResponseDto.getStoreId();
        String stores="45,57,58,49,98,56,75,74,88,112,119,166,167,169,171,172";
        String[] split = stores.split(",");
        List<String> list = Arrays.asList(split);
        if(list.contains(storeId)){
            this.has_c_la_c_banner = false;//是否有c拉c banner
        }
//        this.has_c_la_c_banner = false;//是否有c拉c banner

        this.code_time= 25;

//        this.code_time=  Duration.between(orderDetailResponseDto.getTicketCodeExpireTime(), LocalDateTime.now()).getSeconds()>=0?0:Math.abs(Duration.between(orderDetailResponseDto.getTicketCodeExpireTime(), LocalDateTime.now()).getSeconds());;  //验票码失效时间 秒
    }
}